/*
 * Copyright (C) 2014 Andrey Kulikov (andkulikov@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.transitionseverywhere.utils;

import ohos.agp.animation.Animator;
import ohos.agp.components.Component;
import ohos.agp.render.Path;

import com.transitionseverywhere.PathMotion;


public class AnimatorUtils {

    static class BaseAnimatorCompat {

        public void addPauseListener(Animator animator, Animator.StateChangedListener listener) {
        }

        public void pause(Animator animator) {
        }

        public void resume(Animator animator) {
        }

        public <T> Animator ofPointF(T target, PointFProperty<T> property, float startLeft,
                                     float startTop, float endLeft, float endTop) {
            return PointFAnimator.ofPointF(target, property, startLeft, startTop, endLeft, endTop);
        }

        public <T> Animator ofPointF(T target, PointFProperty<T> property, Path path) {
            return PathAnimatorCompat.ofPointF(target, property, path);
        }

        public boolean isAnimatorStarted(Animator anim) {
            return false;
        }

        public boolean hasOverlappingRendering(Component view) {
            return true;
        }
    }
    private static final BaseAnimatorCompat IMPL;

    static {
        IMPL = new BaseAnimatorCompat();
    }

    public static void addPauseListener(Animator animator, Animator.StateChangedListener listener) {
        IMPL.addPauseListener(animator, listener);
    }

    public static void pause(Animator animator) {
        IMPL.pause(animator);
    }

    public static void resume(Animator animator) {
        IMPL.resume(animator);
    }

    public static <T> Animator ofPointF(T target, PointFProperty<T> property,
                                        float startLeft, float startTop,
                                        float endLeft, float endTop) {
        return IMPL.ofPointF(target, property, startLeft, startTop, endLeft, endTop);
    }

    public static <T> Animator ofPointF(T target, PointFProperty<T> property, Path path) {
        if (path != null) {
            return IMPL.ofPointF(target, property, path);
        } else {
            return null;
        }
    }

    public static <T> Animator ofPointF(T target, PointFProperty<T> property, PathMotion pathMotion,
                                        float startLeft, float startTop, float endLeft, float endTop) {
        if (startLeft != endLeft || startTop != endTop) {
            if (pathMotion == null || pathMotion.equals(PathMotion.STRAIGHT_PATH_MOTION)) {
                return ofPointF(target, property, startLeft, startTop, endLeft, endTop);
            } else {
                return ofPointF(target, property, pathMotion.getPath(startLeft, startTop,
                        endLeft, endTop));
            }
        } else {
            return null;
        }
    }

    public static boolean isAnimatorStarted(Animator anim) {
        return IMPL.isAnimatorStarted(anim);
    }

    public static boolean hasOverlappingRendering(Component view) {
        return IMPL.hasOverlappingRendering(view);
    }
}
